package com.dev.security.manager.controllers;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.dev.security.manager.beans.Permission;
import com.dev.security.manager.service.IPermissionService;
import com.dev.security.util.DataGrid;
import com.dev.security.util.Response;

/**
 * 权限管理
 * @author 潜行的青衣
 * @see
 */
@Controller
@RequestMapping("/manager/permission/")
public class PermissionController {

	@Resource
	private IPermissionService permissionService;
	
	@RequestMapping("browse")
	public @ResponseBody DataGrid<Permission> browse(String app_id, int page, int rows) {
		return new DataGrid<Permission>(this.permissionService.findPager(app_id, page, rows));
	}
	
	@RequestMapping("add")
	public @ResponseBody Response add(Permission perm) {
		if(this.permissionService.save(perm)) {
			return new Response(true);
		} else {
			return new Response(
					new StringBuilder("该应用已经存在别名为“")
						.append(perm.getAlias())
						.append("”的权限！").toString());
		}
	}
	
	@RequestMapping("remove")
	public @ResponseBody Response remove(String[] ids) {
		this.permissionService.remove(ids);
		return new Response(true);
	}
}
